package com.alipay.config;

import java.io.FileWriter;
import java.io.IOException;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;

/* *
 *类名：AlipayConfig
 *功能：基础配置类
 *详细：设置帐户有关信息及返回路径
 *修改日期：2017-04-05
 *说明：
 *以下代码只是为了方便商户测试而提供的样例代码，商户可以根据自己网站的需要，按照技术文档编写,并非一定要使用该代码。
 *该代码仅供学习和研究支付宝接口使用，只是提供一个参考。
 */

public class AlipayConfig {

//↓↓↓↓↓↓↓↓↓↓请在这里配置您的基本信息↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

    // 应用ID,您的APPID，收款账号既是您的APPID对应支付宝账号
    public static String app_id = "2021000117689422";

    // 商户私钥，您的PKCS8格式RSA2私钥
    public static String merchant_private_key ="MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCPYHKRSQlELWIymYnnsKeBSY+74e0ZSPIDUeWhVAd3p2wsAwpHQjhUU/KpW6B6RzUhXNyx75Rr4PDvC02+6XRcWMyUoZ/6n3D7VMziQvDPwyKnPG0KXhoBuVSkqbmmaDd9aXzl/WgEYmwZDwTswhKzm69Q6N2wPhy96NIyt7UmAM1bR6uryNdv26u5uKITMdOkbuAdfkDVMuzppPm9Y6+HQXRin5XX5bfBk7L5FPSGdpKwgcedjuMkmxx9zEr2TWVFbTCyIzpoMR/qK/rgLYu5iFFTrvbScWpTMbOxTqwdvr2e/rSQzubzoiSNTJZciya2odbPz5z4ivvVEhHZE0m/AgMBAAECggEBAIPNL8SrFV+dMMY/KuzYEkPhscYPvHwf+IpgwO17Z5nxSJl0+f/juhCbU1mop2+BAjB3Q1I3YYOCNzoodAHqblNuNjL0GTK1W5FPtUDSNLlpMvP1sm9zbgjjrBHrDIUTDN+3F1/9gZ92MtUeX3KePb7qgVGpoBGiJ53U51ZEVrxlYrW/PGbQUetu3lraVTRRpxWLN4fDXK3vGP0Y1oxJoDgUuUnbj8P1ncNODc/UVkIH32WJVjOxKFGpJhE4rJyOCJocXWUQgDCvT0CPg6FEwk538dD8u/uN+NjLtKQIHQ3SN933+psAV+YxtknP51gvZyEYLo6p/Sa/inkF5BHkILECgYEA0a1evO8A7fFyeVD9wXsKHhT8t3rBsF52fNrGvgH4k2J1QQyF5CYD/1LJt9kEkjjOpr9cogym90n+GgUa/cIO67h+nA0BpK8nUJyYNOI94fYvRNH1fw9KNnY/6SPr0G+HTKTjQ0EXPydmstFwzTL9aguI+8tw3L5mTuZPKgh8X+UCgYEArw1ZIQXUsv54qBSTNMTlYYw07CxbecadRRSUbxeZzGmDLycQ7N8yw2InCw1KStZjOOgkX96reuFLnusn1Kou70Ve3WLTkDpNbroMd9hR+bhbtSnuyIFXTWXTy0ASe7lwCuacwNGwdBLdY7JDTznB0ZKQm/aTIuiQNdDAa1jLQNMCgYBMwL/rPToD39xdmE4rYxTDCj+wElmQbCPHdHZH24TYvrPZSfJBH8Fa1z1L9T79H5pV47rO/v6niwhfEftdZIn9s511FjXByPQFSC1XPnIUov+Om6TYDArIgOTIPQP3WrwWTE18svkFfzDSyGQYWU/2X56XPVNlGrVssFXONykAGQKBgQConA3OjgQ6yHtFQlQsDr72f4r2NR+DIziWsmTqwGvGhZbzEwjtb2tA4MjEj2+QuAFobcmjgiHfwSQKlWyPHcEJfOMMEMXA9TdiQNgDk5waEWZcEGDMRjDl/v/KlRN4krwF8+zmmNMCaq1N+wV0SSiUCT06zH0asbE99K1yeFuGOwKBgHCvFFN5vQdW1HnYtcW7DHSV4wn4kj2JnjbR2b4NcD092eaUZpoQZ/1pm7dWP+nL5HTO3yYp+gWkHXzFCWRYIZoPHx+NVapZZL2Bnonzp2i765rjNd1VwpBGVERDpsuxf73D/4XPJBF85Y40TuzSK4peGaErm0rPdW/2BwyyDzZN";
    // 支付宝公钥,查看地址：https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
    public static String alipay_public_key ="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiK39p2nxi7I3NYVUMLTQhaQwPjZEDpAI/CP5MW7ch4WYWtnHCFKlbkAHGJle21nZ2ZnY46FmYX39owQM5QWbPWU59HL7kuN5L7tP/Ir7BTAfUw15/8Tkca0yClT9oj382qVOdZZfEcxiwLurdTDtuI//FDvnOlEanaxdQzrs10tzxk7KMqZDP6VYsvGODJj3xRU9EOXDZ14PC6dfiAgNv97chAT4LA/PjD7jR8ihBwAUQ0WLtSbpmX7II4zmtWT65BP2/m9ExsYsy9f4rdtBGMMflDnhl3xnuS67ISlKw2qFdSqJKn0smst0E8gUS/uvPT0dLOwwdkrRIgJtW/tJbQIDAQAB";
    // 服务器异步通知页面路径  需http://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
    public static String notify_url = "http://localhost:8989/alipay.trade.page.pay-JAVA-UTF-8/notify_url.jsp";

    // 页面跳转同步通知页面路径 需http://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
    public static String return_url = "http://localhost:8989/dangdang/return_url.jsp";

    // 签名方式
    public static String sign_type = "RSA2";

    // 字符编码格式
    public static String charset = "utf-8";

    // 支付宝网关
    // 请求网关地址  真实环境网关：https://openapi.alipay.com/gateway.do
    //	         沙箱环境网关：https://openapi.alipaydev.com/gateway.do
    public static String gatewayUrl = "https://openapi.alipaydev.com/gateway.do";

    //获得初始化的AlipayClient
    public static AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, "json", AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);
    // 日志记录目录
    public static String log_path = "C:\\";


//↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

    /**
     * 写日志，方便测试（看网站需求，也可以改成把记录存入数据库）
     * @param sWord 要写入日志里的文本内容
     */
    public static void logResult(String sWord) {
        FileWriter writer = null;
        try {
            writer = new FileWriter(log_path + "alipay_log_" + System.currentTimeMillis()+".txt");
            writer.write(sWord);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}